# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

_realname=librist
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.2.11
pkgrel=1
pkgdesc='A library that can be used to add the RIST protocol to applications (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://code.videolan.org/rist/librist/'
license=('spdx:BSD-2-Clause')
depends=(
  "${MINGW_PACKAGE_PREFIX}-cjson"
  "${MINGW_PACKAGE_PREFIX}-libwinpthread-git"
  "${MINGW_PACKAGE_PREFIX}-mbedtls"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-cmake"
  "${MINGW_PACKAGE_PREFIX}-cmocka"
  "${MINGW_PACKAGE_PREFIX}-lz4"
  "${MINGW_PACKAGE_PREFIX}-meson"
  "${MINGW_PACKAGE_PREFIX}-ninja"
  "${MINGW_PACKAGE_PREFIX}-pkgconf"
  "${MINGW_PACKAGE_PREFIX}-winpthreads-git"
)
source=("https://code.videolan.org/rist/librist/-/archive/v${pkgver}/${_realname}-v${pkgver}.tar.bz2")
sha256sums=('f254842900a9dd20fb477b05ea0cce3ec1a8004d85177eef2408eefddca68b86')

build() {
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/meson.exe setup \
      --prefix="${MINGW_PREFIX}" \
      --wrap-mode=nodownload \
      --auto-features=enabled \
      --buildtype=plain \
      --default-library=static \
      -Dhave_mingw_pthreads=true \
      "${_realname}-v${pkgver}" \
      "build-${MSYSTEM}-static"

  ${MINGW_PREFIX}/bin/meson.exe compile -C "build-${MSYSTEM}-static"

  # shared build defines LIBRIST_BUILDING_DLL macro
  LDFLAGS+=" -pthread" \
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/meson.exe setup \
      --prefix="${MINGW_PREFIX}" \
      --wrap-mode=nodownload \
      --auto-features=enabled \
      --buildtype=plain \
      --default-library=shared \
      -Dhave_mingw_pthreads=true \
      "${_realname}-v${pkgver}" \
      "build-${MSYSTEM}-shared"

  ${MINGW_PREFIX}/bin/meson.exe compile -C "build-${MSYSTEM}-shared"
}

package() {
  ${MINGW_PREFIX}/bin/meson.exe install -C "build-${MSYSTEM}-static" --destdir "${pkgdir}"
  ${MINGW_PREFIX}/bin/meson.exe install -C "build-${MSYSTEM}-shared" --destdir "${pkgdir}"

  install -Dm644 "${srcdir}/${_realname}-v${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
